#include "h.hpp"
#include "cnsss/pure-forCnsss.hpp"
#include "pure-mock.hpp"

using namespace pure;


BOOST_AUTO_TEST_SUITE(test_mockedCnsss, MY_TEST_THIS);
BOOST_AUTO_TEST_CASE(test_mockedCnsss_primary){
  mockedCnsss::A ch;
  ICnsssPrimaryBased * c = dynamic_cast<ICnsssPrimaryBased*>(&ch);
  BOOST_CHECK(c->is_primary());
  auto r = c->handle_execute("some-user","some-command");
  BOOST_CHECK(r);
  BOOST_CHECK_EQUAL(r.value(),"Primary result (ignored)");
}

BOOST_AUTO_TEST_CASE(test_mockedCnsss_sub){
  mockedCnsss::A ch{false};     // sub node
  ICnsssPrimaryBased * c = dynamic_cast<ICnsssPrimaryBased*>(&ch);
  BOOST_CHECK(not c->is_primary());
  auto r = c->handle_execute("some-user","some-command");
  BOOST_CHECK(r);
  BOOST_CHECK_EQUAL(r.value(),"Sub result (ignored)");
}

BOOST_AUTO_TEST_CASE(test_endpoint_json){
  // 1. get some random string
  string s1{"aa"}, s2{"bb"}, s3{"\x01\x02"};

  // 2. merge
  string o = SignedData::serialize_3_strs(s1,s2,s3);

  // 3. parse ttd
  optional<json::object> r = SignedData::parse_3_strs_to_json_endpoint(o, "s1", "s2", "s3");
  // text/text/binery
  BOOST_CHECK(r);
  BOOST_CHECK_EQUAL(r.value().size(),3);
  json::object o1 = r.value();
  BOOST_CHECK_EQUAL(o1["s1"].as_string(),s1);
  BOOST_CHECK_EQUAL(o1["s2"].as_string(),s2);
  BOOST_CHECK_EQUAL(o1["s3"].as_string(),"0102");
}

BOOST_AUTO_TEST_SUITE_END();
